﻿#region 命名空间

using System.Web.Http;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.WebUI.Controllers.Api
{
    public class CommentController : ApiController
    {
        /// <summary>
        ///     发送评论
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result Post(Comment model)
        {
            if (UserManage.Current != null)
                model.UserName = UserManage.Current.UserName;

            model.Content = System.Web.HttpContext.Current.Server.HtmlEncode(model.Content);
            model.IP = Common.HttpClient.GetIP();

            var resu = new CommentManage().Add(model);
            if (string.IsNullOrEmpty(resu.Errors) == false)
            {
                return resu;
            }
            if (model.Pass == false)
            {
                resu.Errors = "您的评论待审核后才会显示";
            }
            return resu;
        }

        /// <summary>
        ///     支持或者反对
        /// </summary>
        /// <param name="id"></param>
        /// <param name="support"></param>
        /// <returns></returns>
        public Comment Support(int id, bool support)
        {
            return new CommentManage().SupportOrOppose(id, support);
        }
    }
}